package org.arkeologgr.appening.activities;

import java.util.List;

import org.arkeologgr.appening.adapter.CultureItemListAdapter;
import org.arkeologgr.appening.dataacess.DataAccessManager;
import org.arkeologgr.appening.domain.CultureItem;

import org.arkeologgr.appening.R;
import com.google.android.maps.GeoPoint;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.animation.LayoutAnimationController;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;

public class CultureItemListActivity extends Activity {
	private List<CultureItem> itemList;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_culture_items);
		
		itemList = DataAccessManager.getInstance().getRecentMapItems();
		setupItemsList();
		
		
		
	}
	private String mAreaName = "Lista";
	
	private void setupItemsList() {

		String newTitle = mAreaName + " (" + ((itemList != null) ? itemList.size(): "" )+ ")";
		setTitle(newTitle);
		/*TextView view = (TextView) findViewById(R.id.itemtitle);
		view.setText(newTitle);
		*/
		final ArrayAdapter<CultureItem> listItemAdapter = new CultureItemListAdapter(this,
				R.layout.list_item_cultureitem, itemList);
		this.findViewById(R.id.LLCultureitemLista).setBackgroundColor(Color.WHITE);
		ListView lv = (ListView) this.findViewById(R.id.list_view_id);
		lv.setAdapter(listItemAdapter);
		//lv.setLayoutAnimation(new LayoutAnimationController(mCascadeAnim, 0.5F));
		lv.setOnItemClickListener(new OnItemClickListener() {
		
		    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
			Intent detailView = new Intent(CultureItemListActivity.this,
				DetailsActivity.class);
			detailView.putExtra(CultureItem.ID, itemList.get(position).getId());
			CultureItemListActivity.this.startActivity(detailView);
	
		    }

	
		});
		
		// set listener to turn background loading of logos off when scrolling 
		lv.setOnScrollListener(new OnScrollListener() {
			
			public void onScrollStateChanged(AbsListView view, int scrollState) {
			}
			
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {	}
		});

	}
	

}
